package sh.wn36.vehiclemanage.controller;


import io.swagger.annotations.ApiModelProperty;
import org.apache.velocity.runtime.directive.Break;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import sh.wn36.vehiclemanage.entity.CarPic;
import sh.wn36.vehiclemanage.entity.Dictionary;
import sh.wn36.vehiclemanage.service.CarPicService;
import sh.wn36.vehiclemanage.util.Result;

import java.text.BreakIterator;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xk
 * @since 2021-04-26
 */
@CrossOrigin
@RestController
@RequestMapping("/carPic")
public class CarPicController {

    @ApiModelProperty("成员变量车辆图片")
    @Autowired
    private CarPicService carPicService;

    @ApiModelProperty("通过id拿到所有的车辆图片的内容")
    @GetMapping("/getCarPicById/{id}")
    public Result getBrandById(@PathVariable("id") Integer id){
       CarPic carPic = carPicService.getCarPicByCid(id);

       if(carPic == null){
           CarPic carPic1 = new CarPic();
           carPic1.setCid(id);
           carPic1.setImgPatha("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1026025462,4219514317&fm=26&gp=0.jpg");
           carPic1.setImgPathb("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1026025462,4219514317&fm=26&gp=0.jpg");
           carPic1.setImgPathc("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1026025462,4219514317&fm=26&gp=0.jpg");
           return Result.OK().data("items", carPic1);
       }else {
           return Result.OK().data("items", carPic);
       }
    }

    @ApiModelProperty("通过id拿到所有的车辆图片的内容")
    @PostMapping("/saveCarPic")
    public Result saveCarPic(@RequestBody CarPic carPic){
        System.out.println(carPic);
        if(carPic.getId() == null){
            carPicService.save(carPic);
        }else if(carPic.getId() != null) {
            boolean result = carPicService.updateById(carPic);
        }
        return Result.OK();
    }
}

